<?php


namespace App\Http\Controllers;


use Illuminate\Foundation\Application;

class ContainerController extends Controller
{

    /**
     * larval 还不支持属性注解 只定义变量,和指定属性,而不构造它
     * 需要配合构造方法初始化
     * The application instance being facaded.
     *  Illuminate\Container\Container 不能实现依赖查找
     * @var  \Illuminate\Contracts\Container\Container
     */
    protected  $applcation;

    public function __construct(protected Application $app,protected \Illuminate\Contracts\Container\Container $container){}

    public function appPro()
    {
        dump($this->app->basePath());
        dump($this->container->basePath());
        dump($this->applcation->basePath());

    }

    public function app(Application $app)
    {
        dd($app->basePath());
    }

    /*
     * 直接获取应用容器,当然 最简洁的办法是助手函数app()
     */
    public function UseContainer()
    {
        $basepath = \Illuminate\Container\Container::getInstance()->basePath();
        dump($basepath);
    }

    /**
     * laravel 5.5 开始支持依赖注入
     * @param Application $app
     * @return array
     */

    function container(Application $app)
    {
        $data['$app[config]'] = $app['config']->get('app.env');
        $data['app(config)'] = app('config')->get('app.env');
        $data['path'] = app('path');  //容器内的实例集合属性可以存任何值 这里path就存了根路径
        return $data;
    }

}
